<template>
  <view
    class="content"
    :style="{
      'padding-top': height + 'px',
    }"
  >
    <view
      :style="{
        height: statusBarHeight + 'px',
      }"
    >
    </view>
    <view
      class="head"
      :style="{
        top: statusBarHeight + 'px',
      }"
    >
      <view class="head_left">
        <u-icon
          name="arrow-left"
          color="#FFFFFF"
          size="24"
          :bold="true"
          @click="toBack"
        ></u-icon>
      </view>
      <view class="text" @click="down">我的打卡</view>
    </view>
    <view class="tabs_box">
      <u-tabs
        class="tabs"
        :list="list1"
        @click="tabClick"
        :activeStyle="{
          color: '#eee',
          fontWeight: 'bold',
          transform: 'scale(1.05)',
          'font-size': '34rpx',
        }"
        lineColor="#eee"
        :inactiveStyle="{
          color: '#ADADAD',
          transform: 'scale(1)',
          'font-size': '34rpx',
        }"
        :scrollable="false"
        lineWidth="72rpx"
        lineHeight="4rpx"
      ></u-tabs>
    </view>
    <scroll-view
      :style="{
        height: scrollHeihgt + 'px',
      }"
      :scroll-y="true"
      @scroll="scroll"
      @scrolltolower="scrolltolower"
    >
      <template>
        <view class="clock_box">
          <view
            class="clock_item"
            v-for="(item, index) in list"
            :key="index"
            @click="goDetail(item)"
          >
            <view class="clock_top"> {{ item.title }} </view>
            <view class="clock_center">
              关联课程：{{ item.kecheng[0].title }}
            </view>
            <view class="clock_bom">
              <view class="bom_left">
                完成度{{ item.daka_number }}/{{ item.number }}
              </view>
              <view class="bom_right" v-if="item.status != 3">
                {{ item.status == 1 ? "进行中" : "已完成" }}
              </view>
              <view class="bom_right_y" v-else> 已过期 </view>
            </view>
          </view>

          <view class="empty_view" v-if="list && list.length == 0">
            <image
              class="item_left_clickable"
              src="@/static/images/my/kong.png"
              mode=""
            ></image>
            <view>您还没有打卡记录~</view>
          </view>
        </view>
      </template>
    </scroll-view>


    <floatingBall></floatingBall>
  </view>
</template>

<script>
export default {
  components: {},
  data() {
    return {
      statusBarHeight: 0,
      height: 0,
      list: [],
      list1: [
        {
          name: "进行中",
        },
        {
          name: "已完成",
        },
        {
          name: "已过期",
        },
      ],
      scrollHeihgt: 0,
      current: 0,
      currentIndex: 0,
      itemList: [{}, {}],
      page:1,
      list_page:0
    };
  },
  created() {
    const statusBarHeight = uni.getSystemInfoSync(); // 获取手机状态栏高度
    const windowHeihgt = statusBarHeight.windowHeight;
    this.statusBarHeight = statusBarHeight.statusBarHeight;
    this.$nextTick(() => {
      uni
        .createSelectorQuery()
        .select(".head")
        .boundingClientRect((data) => {
          this.height = data.height;
        })
        .exec();
    });

    this.$nextTick(() => {
      const query = uni.createSelectorQuery().in(this);
      query.select(".head").fields({
        size: true,
      });
      query.select(".tabs_box").fields({
        size: true,
      });

      query.exec((data) => {
        let sum = 0;
        data.forEach((item) => {
          sum += item.height;
        });
        this.scrollHeihgt = windowHeihgt - sum - this.statusBarHeight;
      });
    });

    this.getList(1, this.page);
  },
  onLoad() {},
  methods: {
    tabClick(e) {
      this.list = []
      this.page = 1
      this.last_page = 0
      this.current = e.index;
      if (this.current == 0) {
        // 进行中
        this.getList(1, this.page);
      } else if (this.current == 1) {
        // 已完成
        this.getList(2, this.page);
      } else {
        // 已过期
        this.getList(3, this.page);
      }
    },

    toBack() {
      uni.navigateBack({
        delta: 1,
      });
    },
    getList(num, page) {
      this.$http
        .usergongnengMyDaka({ status: num, page: page })
        .then((res) => {
          console.log(res.data.list, "我的打卡");
          this.list =this.list.concat(res.data.list.data) ;
          this.last_page = res.data.list.last_page
        })
        .catch((error) => {
          console.log(error, "错误");
          uni.$u.toast(error);
        });
    },
    scroll() {},
    scrolltolower() {
      if (this.page == this.last_page || this.last_page == 0) {
      } else {
        this.page++;
        if (this.current == 0) {
          // 进行中
          this.getList(1, this.page);
        } else if (this.current == 1) {
          // 已完成
          this.getList(2, this.page);
        } else {
          // 已过期
          this.getList(3, this.page);
        }
      }
      console.log("触发");
    },
    // 跳详情
    goDetail(item) {
      uni.navigateTo({
        url: `/pages/training/clockDetail?id=${item.id}`,
      });
    },
  },
};
</script>

<style scoped lang="scss">
.content {
  position: fixed;
  box-sizing: border-box;
  background: url("/static/images/index.png") no-repeat;
  background-size: 100% 100%;
}

.head {
  width: 100%;
  padding: 18rpx 30rpx 47rpx;
  position: fixed;
  display: flex;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
  z-index: 99;

  .head_left {
    position: absolute;
    left: 30rpx;
  }

  .head_right {
    position: absolute;
    right: 30rpx;
    font-size: 30rpx;
    font-family: PingFang SC, PingFang SC;
    font-weight: 400;
    color: #55b877;
  }

  .text {
    font-size: 36rpx;
    font-family: PingFang SC-Bold, PingFang SC;
    font-weight: 400;
    color: #ffffff;
  }
}

.clock_box {
  width: 100%;
  padding: 0 30rpx;
  box-sizing: border-box;
  .clock_item {
    width: 100%;
    padding: 32rpx;
    box-sizing: border-box;
    background: rgba(39, 39, 39, 0.5);
    border-radius: 16rpx 16rpx 16rpx 16rpx;
    margin-top: 32rpx;
    .clock_top {
      font-size: 28rpx;
      font-family: PingFang SC, PingFang SC;
      font-weight: 400;
      color: #eeeeee;
    }
    .clock_center {
      font-size: 26rpx;
      font-family: PingFang SC, PingFang SC;
      font-weight: 400;
      color: #d8d8d8;
      margin-top: 18rpx;
    }
    .clock_bom {
      width: 100%;
      display: flex;
      justify-content: space-between;
      margin-top: 32rpx;
      .bom_left {
        font-size: 24rpx;
        font-family: PingFang SC, PingFang SC;
        font-weight: 400;
        color: #adadad;
      }
      .bom_right {
        font-size: 26rpx;
        font-family: PingFang SC, PingFang SC;
        font-weight: 400;
        color: #55b877;
      }
      .bom_right_y {
        font-size: 26rpx;
        font-family: PingFang SC, PingFang SC;
        font-weight: 400;
        color: #adadad;
      }
    }
  }
  .empty_view {
    margin-top: 300rpx;
    image {
      margin: 0 auto;
      width: 410rpx;
      height: 410rpx;
    }
    view {
      font-size: 30rpx;
      color: #d8d8d8;
      text-align: center;
    }
  }
}
</style>